// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StartTrajectoryMessageTest.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Test.Robotics.Manipulation.Runtime.MotionControl
{
    using System;
    using Microsoft.Robotics.Manipulation;
    using Microsoft.Robotics.Manipulation.Runtime.MotionControl;
    using Microsoft.Robotics.Runtime;
    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Test StartTrajectoryMessage
    /// </summary>
    [TestClass]
    public class StartTrajectoryMessageTest
    {
        /// <summary>
        /// Test to create a StartTrajectoryMessage
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void StartMessageTrajectoryConstructorTest()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[2],
                new double[1, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with invalid DOF
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidDOFTest()
        {
            StartTrajectoryMessage cs = new StartTrajectoryMessage(
                0,
                0,
                2,
                new double[1],
                new double[1, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with invalid # of points
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidPointsTest()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                1,
                new double[2],
                new double[1, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with incorrect DOF for target position
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidTargetPosDOF()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[2],
                new double[2, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with incorrect DOF for target velocity
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidTargetVelDOF()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[2],
                new double[1, 2],
                new double[2, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with incorrect # of points for target position
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidTargetPosPoints()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[2],
                new double[1, 1],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with incorrect # of points for target velocity
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidTargetVelPoints()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[2],
                new double[1, 2],
                new double[1, 1],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to create a StartTrajectoryMessage with incorrect # of points in times array
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        [ExpectedException(typeof(ArgumentException))]
        public void StartTrajectoryMessageConstructorInvalidTimePoints()
        {
            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                new double[3],
                new double[1, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);
        }

        /// <summary>
        /// Test to check that ties are properly set by constructor
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void StartTrajectoryMessageGetTimeTest()
        {
            double[] timeIn = new double[] { 0, 2 };

            StartTrajectoryMessage msg = new StartTrajectoryMessage(
                0,
                1,
                2,
                timeIn,
                new double[1, 2],
                new double[1, 2],
                TrajectoryInterpolationMethods.Unspecified,
                false);

            double[] timeOut = new double[2];
            msg.Times.CopyTo(timeOut, 0);

            Assert.AreEqual(timeIn[0], timeOut[0]);
            Assert.AreEqual(timeIn[1], timeOut[1]);
        }
    }
}
